#ifndef _SBOT_PROTOCOL_H_
#define _SBOT_PROTOCOL_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "sbot_protocol_cfg.h"
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

typedef uint8_t  sp_message_p_t;    /* Pointer type of Message */
typedef uint16_t sp_message_size_t; /* The type of sp message size t affects the packet max length */
typedef uint32_t sp_element_id_t;   /* This type affects the maximum number of elements */
typedef uint8_t  sp_element_size_t; /* This type affects the maximum size of a single element */
typedef uint16_t sp_element_map_t;

struct sp_packet {
    uint8_t*          p_message;
    sp_message_size_t size_message; /* Bytes */
    sp_message_size_t size_header;
    sp_element_map_t* element_indexes_map;
};
typedef struct sp_packet* sp_packet_t;

sp_packet_t sbot_protocol_packet_create(void);
void        sbot_protocol_alter(sp_packet_t sp_packet_p, sp_element_id_t element_id, void* value_p);
void        sbot_protocol_get(sp_packet_t sp_packet_p, sp_element_id_t element_id, void* value_p);
void        sbot_protocol_generate_crc(sp_packet_t sp_packet_p);
uint8_t     sbot_protocol_check_crc(sp_packet_t sp_packet_p);
uint8_t     crc8(const unsigned char* data, size_t len);

#ifdef __cplusplus
}
#endif

#endif
